package cn.whdream.juc;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;


public class TestCountDownLatch {
	public static void main(String[] args) {
		CountDownLatch cuCountDownLatch = new CountDownLatch(5);
		Copy c = new Copy(cuCountDownLatch);
		for (int i = 0; i < 5; i++) {
			new Thread(c).start();
		}
	
		long start = System.currentTimeMillis();
		try {
			cuCountDownLatch.await();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		long end = System.currentTimeMillis();
		System.out.println(Thread.currentThread().getName()+"耗费时间："+(end-start));
	}
	private static class Copy implements Runnable{
		private CountDownLatch cu;
		
		public Copy(CountDownLatch cu) {
			super();
			this.cu = cu;
		}
		@Override
		public void run() {
			for (int i = 0; i < 50000; i++) {
				if(i%10 == 0) {
					System.out.println(Thread.currentThread().getName()+"result:"+i);
				}
			}
			cu.countDown();
		}
		
	}
	
}
